import { ConfigManager } from "../../../com/gengine/resource/ConfigManager";
import { TIllustrateCollect } from "../../../Message/Db/Tables/TIllustrateCollect";
import { StringHelper } from "../../../com/gengine/utils/StringHelper";
import { TIllustrateVariety } from "../../../Message/Db/Tables/TIllustrateVariety";
type int = number;
//class IllustrateCollectConfig
    
    export  class IllustrateCollectConfig
    {
        constructor()
        {
            
            this._map = new Map<any, any> /* flash.utils.Dictionary */();
            this._illustrateMap = new Map<any, any> /* flash.utils.Dictionary */();
            this._varMap = new Map<any, any> /* flash.utils.Dictionary */();
            this._varietyMap = new Map<any, any> /* flash.utils.Dictionary */();
            if (IllustrateCollectConfig._instance != null) 
            {
                throw new Error("IllustrateCollectConfig 单例");
            }
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            var loc1=ConfigManager.instance.getJSONByFileName("t_illustrate_collect.json");
            this.write(loc1);
            var loc2=ConfigManager.instance.getJSONByFileName("t_illustrate_variety.json");
            this.writeVariety(loc2);
            return;
        }

        /* internal  */write(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new TIllustrateCollect();
                loc1.attribute = StringHelper.getString(loc2.attribute);
                loc1.broadcast = loc2.broadcast;
                loc1.kind = loc2.category;
                loc1.color = loc2.color;
                loc1.compose = StringHelper.getString(loc2.compose);
                loc1.id = loc2.id;
                loc1.items = StringHelper.getString(loc2.items);
                loc1.name = StringHelper.getString(loc2.name);
                loc1.type = loc2.type;
                loc1.volume = loc2.volume;
                loc1.variety = loc2.variety;
                this._map[loc1.id + "_" + loc1.color] = loc1;
            }
            return;
        }

        /* internal  */writeVariety(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new TIllustrateVariety();
                loc1.desc = loc2.desc;
                loc1.id = loc2.id;
                loc1.levelLimit = loc2.levelLimit;
                loc1.name = loc2.name;
                loc1.variety = loc2.variety;
                loc1.type = loc2.type;
                this._varMap[loc1.id] = loc1;
            }
            return;
        }

        public getIllustrateByVariety(arg1: int, arg2: int=3): Array<any>
        {
            var loc1=null;
            var loc2=null;
            if (this._illustrateMap[arg1] == null) 
            {
                loc1 = [];
                var loc3=0;
                var loc4=this._map;
                for(loc2 of loc4) 
                {
                    if (!(loc2 && loc2.variety == arg1 && loc2.color == arg2)) 
                    {
                        continue;
                    }
                    loc1.push(loc2);
                }
                loc1.sortOn("id", Array.NUMERIC);
                this._illustrateMap[arg1] = loc1;
            }
            return this._illustrateMap[arg1];
        }

        public getIllustrateByType(arg1: int): Array<any>
        {
            var loc1=null;
            var loc2=null;
            if (this._varietyMap[arg1] == null) 
            {
                loc1 = [];
                var loc3=0;
                var loc4=this._varMap;
                for(loc2 of loc4) 
                {
                    if (loc2 && loc2.type == arg1) 
                    {
                        loc1.push(loc2);
                    }
                    this._varietyMap[arg1] = loc1;
                }
            }
            return this._varietyMap[arg1];
        }

        public getIllustrateByIdColor(arg1: int, arg2: int): TIllustrateCollect
        {
            return this._map[arg1 + "_" + arg2];
        }

        public static get instance(): IllustrateCollectConfig
        {
            if (IllustrateCollectConfig._instance == null) 
            {
                IllustrateCollectConfig._instance = new IllustrateCollectConfig();
            }
            return IllustrateCollectConfig._instance;
        }

        /* internal */ /* var */_map: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_illustrateMap: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_varMap: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_varietyMap: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ static /* var */_instance: IllustrateCollectConfig;
    }
